﻿using GCC.Container.Abstracts;

namespace Z.Test.JobDemo
{
    public class JobDemo4 : AbsJobBase
    {
        public JobDemo4(AbsGCCLogger logger) : base(logger)
        {
            Name = "我是测试job4,每秒输出一次时间,我是单例的,所以我还能动态改我得执行间隔";
            Interval = new TimeSpan(0, 0, 1);
            JobType = GCCJobTypeEnum.Singleton;
        }

        public override Task Start(AbsGCCContext context)
        {
            return Task.Run(async () =>
            {
                Interval = Interval!.Value.Add(new TimeSpan(0, 0, 1));
                Console.WriteLine($" 我是JOB:{Name} JOBID:{ID} 本次的EVENTID:{context.EventID} 当前时间:{DateTime.Now},下次执行的时间间隔:{Interval}");
                Console.WriteLine($" 由于我是非依赖的,我这里沉睡3秒,没有影响");
                await Task.Delay(1000 * 3);
            }, _cancellToken.Token);
        }

        protected override void Dispose(bool flag)
        {
            Console.WriteLine($" 我是JOB:{Name} 我被销毁了.");
            base.Dispose(flag);
        }
        public override Task Stop()
        {
            return Task.Run(() =>
            {
                Logger.Information($"Job {Name} stoping.");
                _cancellToken.Cancel();
                Logger.Information($"Job {Name} stoped.");
            });
        }
    }
}